package com.mzy.xmyx.common.exception;

import com.mzy.xmyx.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result error(Exception e) {
        e.printStackTrace();
        return Result.fail(null);
    }

    /**
     * 自定义异常处理方法
     *
     * @param e
     * @return Result
     */
    @ExceptionHandler(XmyxException.class)
    public Result error(XmyxException e) {
        return Result.build(null, e.getCode(), e.getMessage());
    }
}
